package com.example.demo.executor;

import com.gj.executor.support.ResizableCapacityLinkedBlockingQueue;
import com.hippo4j.executor.DynamicThreadPool;
import com.hippo4j.executor.DynamicThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolExecutorAutoConfiguration {

    @DynamicThreadPool
    @Bean
    public DynamicThreadPoolExecutor executor() {
        DynamicThreadPoolExecutor dynamicThreadPoolExecutor = new DynamicThreadPoolExecutor(
                "1",
                1, 10, 10, TimeUnit.SECONDS,
                new ResizableCapacityLinkedBlockingQueue<>(100),
                r -> new Thread(r),
                new ThreadPoolExecutor.AbortPolicy(),
                false);

        return dynamicThreadPoolExecutor;
    }
}
